import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { WebManageConst } from "src/consts/web_manage_const";
@Component({})
export default class WebMConfigPanel extends MyVue {
    name: string = 'WebMConfigPanel';
    formData: any;
    footerFlag: boolean = true;
    itemData: any[];
    title: String;
    titleIcon: String;
    isOther: Boolean;
    featureCode: string

    initData(that?: any): void {
        that.featureCode = Config.featureCode2 + 'web.entity.WebConfig'
        var index = WLStore().state.webMShow.config_index
        var type = WLStore().state.webMShow.login_type
        if (WLStore().state.webMShow.config_type == "edit") {
            that.formData = WLStore().state.webMShow[type + 'Configs'][index];
            that.title = "配置信息详情"
            that.titleIcon = "btn_xq"
        } else {
            that.formData = {}
            that.formData.shi = "shi"
            that.formData.handle_type = ""
            that.title = "新增配置信息"
            that.titleIcon = "pop_xz"
        }

        if (that.formData.config_type == "other" || that.formData.config_type == "select") {
            that.isOther = false
        } else {
            that.isOther = true
        }

        var dataList = WLStore().state.webMShow[type + 'Configs']
        var list = enumList("com.wlfun.assist.module.web.entity.WebConfig", "config_type")
        var selectList = []
        for (let i = 0; i < list.length; i++) {
            if (type == "account") {
                if (list[i].opKey != "pin") {
                    var flag = true
                    for (let k = 0; k < dataList.length; k++) {
                        if (list[i].opKey == dataList[k].config_type) {
                            if (list[i].opKey != "login" && list[i].opKey != "select" && list[i].opKey != "other") {
                                if (k !== index) {
                                    flag = false
                                }
                            }
                        }
                    }

                    if (flag) {
                        selectList.push(list[i])
                    }
                }
            } else if (type == "ca") {
                if (list[i].opKey == "pin" || list[i].opKey == "other") {
                    var flag = true
                    for (let k = 0; k < dataList.length; k++) {
                        if (list[i].opKey == dataList[k].config_type) {
                            if (list[i].opKey != "other") {
                                if (k !== index) {
                                    flag = false
                                }
                            }
                        }
                    }

                    if (flag) {
                        selectList.push(list[i])
                    }
                }
            } else if (type == "caAndAccount") {
                var flag = true
                for (let k = 0; k < dataList.length; k++) {
                    if (list[i].opKey == dataList[k].config_type) {
                        if (list[i].opKey != "login" && list[i].opKey != "select" && list[i].opKey != "other") {
                            if (k !== index) {
                                flag = false
                            }
                        }
                    }
                }

                if (flag) {
                    selectList.push(list[i])
                }
            }
        }
        that.itemData = selectList
    }

    mounted(): void {
    }


    configChange(val: String): void {
        if (val == "login" || val == "select" || val == "captchare") {
            this.formData.handle_type = "click"
        } else {
            this.formData.handle_type = "input"
        }

        if (val == "other" || val == "select") {
            this.isOther = false
        } else {
            this.isOther = true
        }

        if (val == "captchare") {
            this.formData.shi = "fou"
        }
    }

    editConfig(): void {
        this.$refs.webMConfigForm.validate((valid: Boolean) => {
            if (valid) {
                var sendData = this.formData
                if (sendData.shi == "shi") {
                    sendData.must = true
                } else if (sendData.shi == "fou") {
                    sendData.must = false
                }
                WLCommit(WebManageConst.CommitConfigData, this.formData)
            } else {
                WLMessage("必填字段为空,无法保存网站配置信息", "warning")
                return false;
            }
        })
    }

    continueConfig(): void {
        this.$refs.webMConfigForm.validate((valid: Boolean) => {
            if (valid) {
                var sendData = JSON.parse(JSON.stringify(this.formData))
                sendData.isContinue = true
                if (sendData.shi == "shi") {
                    sendData.must = true
                } else if (sendData.shi == "fou") {
                    sendData.must = false
                }
                WLCommit(WebManageConst.CommitConfigData, sendData)

                setTimeout(() => {
                    this.$refs.webMConfigForm.resetFields();
                }, 500);
            } else {
                WLMessage("必填字段为空,无法保存网站配置信息", "warning")
                return false;
            }
        })
    }
}